package cjyyp.day03;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

public class 字段更新器 {
    public static void main(String[] args) {
        Student student=new Student("叶航",20);
        AtomicReferenceFieldUpdater fieldUpdater=AtomicReferenceFieldUpdater.newUpdater(Student.class,String.class,"name");
        boolean flag = fieldUpdater.compareAndSet(student, "叶航", "马儿");
        System.out.println(flag);
        System.out.println(student);
    }
}
@Data
@AllArgsConstructor
@NoArgsConstructor
class Student{
    volatile String name;
    volatile Integer age;

}